package com.dotc.kotlinmvvmdemo.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

public class ActivityCollector {

    /**
     * 创建一个集合保存
     */
    public static List<Activity> activities = new ArrayList<>();



    /**
     * 获取 Activity数量
     * @param
     */
    public static int getActivity(){
      return activities.size();
    }
    /**
     * 添加 Activity
     * @param activity
     */
    public static void addActivity(Activity activity){
        activities.add(activity);
    }

    /**
     * 移除 Activity
     * @param activity
     */
    public static void removeActivity(Activity activity){
        activities.remove(activity);
    }

    /**
     * 移除所有 Activity
     *
     */
    public static void finishAll(){
        for (Activity activity:activities){
            if (!activity.isFinishing()){
                activity.finish();
            }
        }
        activities.clear();
    }
}
